﻿using System;
using System.ComponentModel;
using System.Linq;
using Inaction.Core;
using Inaction.Mapping;
using System.ComponentModel.DataAnnotations;

namespace Inaction.Business.Security
{
    [Table("AssemblyClassResource"), DisplayName("程序集类资源"), Serializable]
    public class AssemblyClassResource : Abstract.AssemblyClassResource<AssemblyClassResource>
    {
        #region 子表

        [Display(Description = "程序集类资源角色"), DisplayName("程序集类资源角色")]
        public AssemblyClassResourceRoleList AssemblyClassResourceRoles
        {
            get { return GetChild<AssemblyClassResourceRoleList, AssemblyClassResourceRole>(); }
        }

        #endregion

        public void RefreshExecuteRoles(RoleInfo role)
        {
            var item = AssemblyClassResourceRoles.FirstOrDefault(p => p.RoleId == role.Id);
            if (item == null)
            {
                item = AssemblyClassResourceRoles.AddNew();
                item.RoleId = role.Id;
            }
            item.AllowExecute = role.Selected;
        }
    }

    [DisplayName("程序集类资源列表"), Serializable]
    public class AssemblyClassResourceList : Inaction.Business.EntityList<AssemblyClassResourceList, AssemblyClassResource>
    {
    }
}
